package com.inibb.app.vo;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

import com.inibb.app.dao.criteria.SortOrder;
import com.inibb.app.pagination.dto.PageFilter;
import com.inibb.app.pagination.dto.PageSorter;

@SuppressWarnings("serial")
public class BaseSearchCriteria implements Serializable {

	// private transient Logger logger = LoggerFactory.getLogger(this.getClass());
	
	private String orderBy;
	
	private SortOrder sortOrder = SortOrder.unsorted;
	
	private int startRow = 0;
	
	private int pageSize = 10;
	
	//for mvc
	private PageFilter pageFilter = new PageFilter( );
	private PageSorter pageSorter = new PageSorter( );
	
//	private Map<String, Object> filter = new HashMap<String, Object>();
	
	

	
//	public void addFilter(String key,Object value){
//		filter.put(key, value);
//	}

	public String getOrderBy() {
		return orderBy;
	}

	public void setOrderBy(String orderBy) {
		this.orderBy = orderBy;
	}

	public SortOrder getSortOrder() {
		return sortOrder;
	}

	public void setSortOrder(SortOrder sortOrder) {
		this.sortOrder = sortOrder;
	}

	public int getStartRow() {
		return startRow;
	}

	public void setStartRow(int startRow) {
		this.startRow = startRow;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public SortOrder getChangableSortOrder() {
		
		if(sortOrder == SortOrder.unsorted){
			// logger.debug("changing sort order to {}", SortOrder.ascending);
			return SortOrder.ascending;
		}
		
		if(sortOrder == SortOrder.ascending){
			// logger.debug("changing sort order to {}", SortOrder.descending);
			return SortOrder.descending;
		}
		if(sortOrder == SortOrder.descending){
			// logger.debug("changing sort order to {}", SortOrder.unsorted);
			return SortOrder.unsorted;
		}
		// logger.debug("changing sort order to {}", SortOrder.unsorted);
		
		return SortOrder.unsorted;
	}
	
	public String getSortOrderStr(){
		if(this.sortOrder == SortOrder.ascending){
			return "asc";
		}
		if(this.sortOrder == SortOrder.descending){
			return "desc";
		}
		return null;
		
	}

	public PageFilter getPageFilter() {
		return pageFilter;
	}

	public void setPageFilter(PageFilter pageFilter) {
		this.pageFilter = pageFilter;
	}

	public PageSorter getPageSorter() {
		return pageSorter;
	}

	public void setPageSorter(PageSorter pageSorter) {
		this.pageSorter = pageSorter;
	}

//	public Map<String, Object> getFilter() {
//		return filter;
//	}
//
//	public void setFilter(Map<String, Object> filter) {
//		this.filter = filter;
//	}
	
}
